//
//  DolphinInfoString.hpp
//  client
//
//  Created by will on 24/02/2017.
//
//
#ifdef USE_GCLOUD

#ifndef DolphinInfoString_hpp
#define DolphinInfoString_hpp

#include <stdio.h>
#include "GCloud/GCloudDolphinInterface.h"
#include "GCloud/GCloudPublicDefine.h"
#include "GCloud/gcloud_dolphin_errorcode_check.h"

#include "base/CCConsole.h"

class DolphinInfoString
{
public:
    std::string strUpdateInfoDefault = "正在为您检查更新";
    std::string strUpdateInfoGettingAppVersion = "获取程序版本信息";
    std::string strUpdateInfoGettingSrcVersion = "获取资源版本信息";
    std::string strUpdateInfoFirstExtract = "正在为您解压资源包（此过程不消耗流量），请耐心等待";
    std::string strUpdateInfoApkDownloadConfig = "下载配置文件";
    std::string strUpdateInfoApkDownDiff = "下载差异文件";
    std::string strUpdateInfoApkDownFull = "下载文件";
    std::string strUpdateInfoApkCheckCompleted = "校验文件";
    std::string strUpdateInfoApkCheckLocal = "校验文件";
    std::string strUpdateInfoApkCheckConfig = "校验文件";
    std::string strUpdateInfoApkCheckDiff = "校验文件";
    std::string strUpdateInfoApkMergeDiff = "合并差异文件";
    std::string strUpdateInfoApkCheckFull = "校验文件";
    
    std::string strUpdateInfoSourceDownloadList = "下载配置文件";
    std::string strUpdateInfoSourcePrepareUpdate = "准备更新";
    std::string strUpdateInfoSourceAnalyseDiff = "正在分析差异";
    std::string strUpdateInfoSourceDownload = "正在为您下载资源";
    std::string strUpdateInfoSourceExtract = "正在为您初始化资源包";

    const std::string&  GetUpdateInfoString(GCloud::dolphinUpdateStage curVersionStage, GCloud::dolphinUpdateInitType updatetype, bool& isDownloading)
    {
        isDownloading = false;
        switch (curVersionStage)
        {
            case GCloud::VS_Dolphin_Version:
            {
                if (updatetype == GCloud::UpdateInitType_OnlySource)
                {
                    return strUpdateInfoGettingSrcVersion;
                }
                else
                {
                    return strUpdateInfoGettingAppVersion;
                }
            }
            case GCloud::VS_FirstExtract:
                return strUpdateInfoFirstExtract;
            case GCloud::VS_ApkUpdateDownConfig:
                isDownloading = true;
                return strUpdateInfoApkDownloadConfig;
            case GCloud::VS_ApkUpdateDownDiffFile:
                isDownloading = true;
                return strUpdateInfoApkDownDiff;
            case GCloud::VS_ApkUpdateDownFullApk:
                isDownloading = true;
                return strUpdateInfoApkDownFull;
            case GCloud::VS_ApkUpdateCheckCompletedApk:
                return strUpdateInfoApkCheckCompleted;
            case GCloud::VS_ApkUpdateCheckLocalApk:
                return strUpdateInfoApkCheckLocal;
            case GCloud::VS_ApkUpdateCheckConfig:
                return strUpdateInfoApkCheckConfig;
            case GCloud::VS_ApkUpdateCheckDiff:
                return strUpdateInfoApkCheckDiff;
            case GCloud::VS_ApkUpdateCheckFull:
                return strUpdateInfoApkCheckFull;
            case GCloud::VS_SourceUpdateDownloadList:
                isDownloading = true;
                return strUpdateInfoSourceDownloadList;
            case GCloud::VS_SourcePrepareUpdate:
                return strUpdateInfoSourcePrepareUpdate;
            case GCloud::VS_SourceAnalyseDiff:
                return strUpdateInfoSourceAnalyseDiff;
            case GCloud::VS_SourceDownload:
                isDownloading = true;
                return strUpdateInfoSourceDownload;
            case GCloud::VS_SourceExtract:
                return strUpdateInfoSourceExtract;
            default:
                return strUpdateInfoDefault;
        }
    }
};


class DolphinErrorString
{
public:
    std::string strUpdateErrorDefault = "更新失败";
    std::string strUpdateErrorNetError = "网络错误，请确认网络状态后重试";
    std::string strUpdateErrorNetTimeOut = "网络超时，请确认网络状态后重试";
    std::string strUpdateErrorNoSpace = "磁盘空间不足，请清理空间后重试";
    std::string strUpdateErrorOtherSystemError = "系统错误，请重启手机";
    std::string strUpdateErrorOtherError = "系统错误，请重启手机";
    std::string strUpdateErrorNotSupport = "当前版本不支持更新，请到市场上下载最新版本";
    std::string strUpdateErrorNotSure = "未知错误，检查网络，检查磁盘空间后重启更新";//不存在
    std::string strUpdateErrorNetNotSupport = "当前的环境下载异常，请到市场下载最新版本";

    const std::string& getUpdateErrorString(int code)
    {
        gcloud::dolphin::IIPSMobileErrorCodeCheck codeCheck;
        gcloud::dolphin::ErrorCodeInfo info = codeCheck.CheckIIPSErrorCode(code);

        cocos2d::log("===>InstallLayerDolphin getUpdateErrorString code=%d, first=%d, second=%d, error=%d, inside=%d", 
            code, info.m_nFirstModule, info.m_nSecondModule, info.m_nErrorType, info.m_nInsideErrorType);

        switch (info.m_nErrorType)
        {
            case gcloud::dolphin::error_type_network:
                return strUpdateErrorNetError;
            case gcloud::dolphin::error_type_net_timeout:
                return strUpdateErrorNetTimeOut;
            case gcloud::dolphin::error_type_device_hasno_space:
                return strUpdateErrorNoSpace;
            case gcloud::dolphin::error_type_other_system_error:
                return strUpdateErrorOtherSystemError;
            case gcloud::dolphin::error_type_other_error:
                return strUpdateErrorOtherError;
            case gcloud::dolphin::error_type_cur_version_not_support_update:
                return strUpdateErrorNotSupport;
            case gcloud::dolphin::error_type_cur_net_not_support_update:
                return strUpdateErrorNetNotSupport;
            default:
                return strUpdateErrorDefault;
        }
    }
};

#endif /* DolphinInfoString_hpp */

#endif
